package com.hgy.chapter3.aspect;

import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hgy.framework.annotation.Aspect;
import com.hgy.framework.annotation.Controller;
import com.hgy.framework.proxy.AspectProxy;

/**
 * 拦截 Controller 所有方法
 * 
 * @author alone
 *
 */
@Aspect(value = Controller.class, loadOnStartup = 0)
public class ControllerAspect extends AspectProxy{
	
	private static final Logger LOOGER = LoggerFactory.getLogger(ControllerAspect.class);
	
	private long begin;
	
	@Override
	public void before(Class<?> cls, Method method, Object[] params) {
		LOOGER.debug("----------begin-------------");
		LOOGER.debug(String.format("class: %s", cls.getName()));
		LOOGER.debug(String.format("method: %s", method.getName()));
		begin = System.currentTimeMillis();
	}
	
	@Override
	public void after(Class<?> cls, Method method, Object[] params) {
		LOOGER.debug(String.format("time: %dms", System.currentTimeMillis()- begin));
		LOOGER.debug("------------end-------------");
	}
	
	
	
}
